package com.wkhyapp.lm.contract;

import com.wkhyapp.lm.base.BasePresenter;
import com.wkhyapp.lm.http.ApiCallback;
import com.wkhyapp.lm.http.net.GoodsListRequest;
import com.wkhyapp.lm.http.net.SearchRequest;
import com.wkhyapp.lm.http.net.SuperResponse;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.http.vo.Member;
import com.wkhyapp.lm.utils.MemberUtils;

/**
 * Created by Administrator on 2021-10-6.
 */

public class SearchResultPresenter extends BasePresenter<SearchResultView> {

    public SearchResultPresenter(SearchResultView searchResultView) {
        super(searchResultView);
    }



    public void getShop(String key){
        SearchRequest request = new SearchRequest();
        request.setKey(key);
        if(MemberUtils.isLogin()){
            request.setUserId(MemberUtils.getUid());
        }
        addSubscription(apiStores.searchShop(request),new ApiCallback<SuperResponse<Member>>() {
            @Override
            public void onSuccess(SuperResponse<Member> response) {
                mvpView.setMember(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void getDate(String imgUrl,int pageNo){
        GoodsListRequest request = new GoodsListRequest();
        request.setPageNo(pageNo);
        request.setPageSize(12);
        request.setImgUrl(imgUrl);
        addSubscription(apiStores.searchByPicture(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoods(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void getDateMore(int pageNo,String imgUrl){
        GoodsListRequest request = new GoodsListRequest();
        request.setPageNo(pageNo);
        request.setPageSize(12);
        request.setImgUrl(imgUrl);
        addSubscription(apiStores.searchByPicture(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoodsMore(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void getSearchDate(String ket,int pageNo){
        SearchRequest request = new SearchRequest();
        request.setPageNo(pageNo);
        request.setPageSize(12);
        request.setKey(ket);
        addSubscription(apiStores.search(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoods(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void getSearchDateMore(String ket,int pageNo){
        SearchRequest request = new SearchRequest();
        request.setPageNo(pageNo);
        request.setPageSize(12);
        request.setKey(ket);
        addSubscription(apiStores.search(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoodsMore(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

}
